# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=assimp

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgver=r2029.bd0c283
pkgrel=1
pkgdesc="Portable Open Source library to import various well-known 3D model formats in an uniform manner (mingw-w64)"
arch=('any')
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-boost" "${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake" "${MINGW_PACKAGE_PREFIX}-gcc" 'unzip')
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
url=('http://assimp.sourceforge.net/index.html')
source=("${_realname}"::"git+https://github.com/assimp/assimp.git"
        'build-fixes.patch')
options=(!strip staticlibs)
md5sums=('SKIP'
         '8627cd14b63ff5ea524c1a9ba62ebbce')

pkgver() {
  cd "$srcdir/$_realname"
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd ${_realname}
  patch -p1 -i ${srcdir}/build-fixes.patch
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}
  
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX:PATH=${pkgdir}${MINGW_PREFIX} \
    -DASSIMP_BUILD_ASSIMP_TOOLS=YES \
    -DASSIMP_ENABLE_BOOST_WORKAROUND=OFF \
    -DASSIMP_BUILD_STATIC_LIB=OFF \
    -DCMAKE_BUILD_TYPE=RELEASE \
    -DASSIMP_BUILD_TESTS=OFF \
    -DDirectX_DXERR_LIBRARY=${MINGW_PREFIX}/${MINGW_CHOST}/lib/libdxerr9.a \
    ../${_realname}
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make -j1 install

  install -Dm644 "${srcdir}/${_realname}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
